<div [@routerTransition]>
  <div class="m-subheader ">
    <div class="d-flex align-items-center">
      <div class="mr-auto col-xs-6">
        <h3 class="m-subheader__title m-subheader__title--separator">
          <span>材料管理</span>
        </h3>
        <span class="m-section__sub"> 材料管理的文本头信息 </span>
      </div>
      <div class="col-xs-6 text-right">
        <div class="btn-group">
          <button
            type="button"
            class="btn btn-outline-success dropdown-toggle"
            style="margin-right: 10px;"
            data-toggle="dropdown"
            aria-haspopup="true"
            aria-expanded="false"
          >
            <i class="fa fa-file-excel-o"></i>Excel操作
          </button>
          <div class="dropdown-menu" > 
              <!-- <excel-import
              [showIcon]="false"
              [onlyLink]="true"
              [btnColor]="'success'"
              [btnText]="'导入'"
              (onUpload)="onUpload($event)"
            ></excel-import> -->
              <!-- <excel-import [showIcon]="false" [onlyLink]="true" [btnColor]="'success'"
              [btnText]="'导入(按导出模板)'" (onUpload)="uploadExcel($event)"></excel-import> -->
              <div class="dropdown-divider"></div>
              <a class="dropdown-item" href="javascript:;" (click)="exportToExcel($event)">导出所有数据</a>
          </div>
      </div>
    </div>
  </div>

  <div class="m-content">
    <div class="m-portlet m-portlet--mobile">
      <div class="m-portlet__body">
        <form class="horizontal-form" autocomplete="off">
          <div class="m-form m-form--label-align-right">
            <div class="row align-items-center m--margin-bottom-10">
              <div class="col-xl-12">
                <div class="form-group m-form__group align-items-center">
                  <div class="input-group">
                    <input
                      [(ngModel)]="filterText"
                      name="filterText"
                      autofocus
                      class="form-control m-input"
                      [placeholder]="l('SearchWithThreeDot')"
                      type="text"
                    />
                    <span class="input-group-btn">
                      <button
                        (click)="getMaterials()"
                        class="btn btn-primary"
                        type="submit"
                      >
                        <i
                          class="flaticon-search-1"
                          [attr.aria-label]="l('Search')"
                        ></i>
                      </button>
                    </span>
                  </div>
                </div>
              </div>
            </div>

            <div
              class="row m--margin-bottom-10"
              [hidden]="!advancedFiltersAreShown"
            >
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="TaskCode"
                    class="form-control"
                    [(ngModel)]="TaskCode"
                    placeholder="任务号"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="DrawingCode"
                    class="form-control"
                    [(ngModel)]="DrawingCode"
                    placeholder="图号"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="MaterialName"
                    class="form-control"
                    [(ngModel)]="MaterialName"
                    placeholder="材料名称"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="MaterialStatus"
                    class="form-control"
                    [(ngModel)]="MaterialStatus"
                    placeholder="材料状态"
                  />
                </div>
              </div>

              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="InvFurBatch"
                    class="form-control"
                    [(ngModel)]="InvFurBatch"
                    placeholder="炉批号"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="Hgz_zjd"
                    class="form-control"
                    [(ngModel)]="Hgz_zjd"
                    placeholder="质检单号"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="InvCode"
                    class="form-control"
                    [(ngModel)]="InvCode"
                    placeholder="物资编码"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="PaiHao"
                    class="form-control"
                    [(ngModel)]="PaiHao"
                    placeholder="牌号"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="MaterialSpec"
                    class="form-control"
                    [(ngModel)]="MaterialSpec"
                    placeholder="规格"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="Hgz_zyd"
                    class="form-control"
                    [(ngModel)]="Hgz_zyd"
                    placeholder="质疑单号"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="MaterialSize"
                    class="form-control"
                    [(ngModel)]="MaterialSize"
                    placeholder="尺寸"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="InvMeasName"
                    class="form-control"
                    [(ngModel)]="InvMeasName"
                    placeholder="计量单位"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="TechCondition"
                    class="form-control"
                    [(ngModel)]="TechCondition"
                    placeholder="技术状态"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="ZhuanYongInfo"
                    class="form-control"
                    [(ngModel)]="ZhuanYongInfo"
                    placeholder="专料专用信息"
                  />
                </div>
              </div>
              <div class="col-md-3">
                <div class="form-group">
                  <input
                    type="text"
                    name="HgzNo"
                    class="form-control"
                    [(ngModel)]="HgzNo"
                    placeholder="合格证"
                  />
                </div>
              </div>
            </div>

            <div class="row margin-bottom-10" *ngIf="advancedFiltersAreShown">
              <div class="col-sm-12 text-right">
                <button class="btn btn-metal" (click)="getMaterials()">
                  <i class="fa fa-refresh"></i> {{ l("Refresh") }}
                </button>
              </div>
            </div>
            <div class="row margin-bottom-10">
              <div class="col-sm-12">
                <span
                  class="clickable-item text-muted"
                  *ngIf="!advancedFiltersAreShown"
                  (click)="advancedFiltersAreShown = !advancedFiltersAreShown"
                  ><i class="fa fa-angle-down"></i>
                  {{ l("ShowAdvancedFilters") }}</span
                >
                <span
                  class="clickable-item text-muted"
                  *ngIf="advancedFiltersAreShown"
                  (click)="advancedFiltersAreShown = !advancedFiltersAreShown"
                  ><i class="fa fa-angle-up"></i>
                  {{ l("HideAdvancedFilters") }}</span
                >
              </div>
            </div>
          </div>
        </form>

        <div class="row align-items-center">
          <!-- <Primeng-TurboTable-Start> -->
          <div
            class="primeng-datatable-container"
            [busyIf]="primengTableHelper.isLoading"
          >
            <p-table
              #dataTable
              (onLazyLoad)="getMaterials($event)"
              [value]="primengTableHelper.records"
              rows="{{ primengTableHelper.defaultRecordsCountPerPage }}"
              [paginator]="false"
              [lazy]="true"
              [scrollable]="true"
              ScrollWidth="100%"
              [responsive]="primengTableHelper.isResponsive"
              [resizableColumns]="primengTableHelper.resizableColumns"
            >
              <ng-template pTemplate="header">
                <tr>
                  <th
                    style="width: 130px"
                    [hidden]="!isGrantedAny('Pages.Material.Manage.Operation')"
                  >
                    {{ l("Actions") }}
                  </th>
                  <th style="width: 170px;">任务号</th>
                  <th style="width: 150px;">图号</th>
                  <th style="width: 120px;">材料名称</th>
                  <th style="width: 80px;">数量</th>
                  <th style="width: 120px;">炉批号</th>
                  <th style="width: 120px;">质检单号</th>
                  <th style="width: 120px;">物资编码</th>
                  <th style="width: 80px;">牌号</th>
                  <th style="width: 80px;">材料状态</th>
                  <th style="width: 120px;">规格</th>
                  <th style="width: 120px;">尺寸</th>
                  <th style="width: 120px;">材料类型</th>
                  <th style="width: 120px;">材料来源</th>
                  <th style="width: 120px;">技术状态</th>
                  <th style="width: 120px;">专料专用信息</th>
                  <th style="width: 150px;">合格证</th>
                  <th style="width: 120px;">保管期</th>
                  <th style="width: 120px;">质疑单号</th>
                  <th style="width: 80px;">计量单位</th>
                  <th style="width: 80px;">单价</th>
                  <th style="width: 200px">备注</th>
                </tr>
              </ng-template>
              <ng-template pTemplate="body" let-record="$implicit">
                <tr>
                  <td
                    style="width: 130px"
                    [hidden]="!isGrantedAny('Pages.Material.Manage.Operation')"
                  >
                    <div class="btn-group dropdown" normalizePosition>
                      <button
                        class="dropdown-toggle btn btn-sm btn-primary"
                        data-toggle="dropdown"
                        aria-haspopup="true"
                        aria-expanded="false"
                      >
                        <i class="fa fa-cog"></i><span class="caret"></span>
                        {{ l("Actions") }}
                      </button>
                      <ul class="dropdown-menu">
                        <li>
                          <a
                            (click)="editMaterialModal.show(record.id, $event)"
                            >{{ l("Edit") }}</a
                          >
                        </li>
                        <li>
                          <a
                            (click)="
                              updateMaterialPositionModal.show(
                                record.id,
                                record.materialChargeDetails,
                                $event
                              )
                            "
                            >修改材料位置</a
                          >
                        </li>
                        <li>
                          <a
                            (click)="
                              returnWLModal.show(
                                record.id,
                                record.materialChargeDetails,
                                $event
                              )
                            "
                            >退还物流</a
                          >
                        </li>
                        <li>
                          <a (click)="adjustIntoModal.show(record.id, $event)"
                            >调整库存增</a
                          >
                        </li>
                        <li>
                          <a
                            (click)="
                              adjustOutModal.show(
                                record.id,
                                record.materialChargeDetails,
                                $event
                              )
                            "
                            >调整库存减</a
                          >
                        </li>
                        <li>
                          <a (click)="logMaterialModal.show(record.id)"
                            >查看日志</a
                          >
                        </li>

                        <!--
                          <li>
                            <a (click)="deleteMaterial(record)">{{l('Delete')}}</a>
                          </li>
                        -->
                      </ul>
                    </div>
                  </td>
                  <th style="width: 170px;">{{ record.taskCode }}</th>
                  <th style="width: 150px;">{{ record.drawingCode }}</th>
                  <th style="width: 120px;">{{ record.materialName }}</th>
                  <th style="width: 80px;">{{ record.canUsedQuantity }}</th>
                  <th style="width: 120px;">{{ record.invFurBatch }}</th>
                  <th style="width: 120px;">{{ record.hgz_zjd }}</th>
                  <th style="width: 120px;">{{ record.invCode }}</th>
                  <th style="width: 80px;">{{ record.paiHao }}</th>
                  <th style="width: 80px;">{{ record.materialStatus }}</th>
                  <th style="width: 120px;">{{ record.materialSpec }}</th>
                  <th style="width: 120px;">{{ record.materialSize }}</th>
                  <th style="width: 120px;">{{ record.materialType }}</th>
                  <th style="width: 120px;">{{ record.materialLY }}</th>
                  <th style="width: 120px;">{{ record.techCondition }}</th>
                  <th style="width: 120px;">{{ record.zhuanYongInfo }}</th>
                  <th style="width: 150px;">{{ record.hgzNo }}</th>
                  <th style="width: 120px;">
                    {{ record.baoGuanDate | momentFormat: "YYYY-MM-DD" }}
                  </th>
                  <th style="width: 120px;">{{ record.hgz_zyd }}</th>
                  <th style="width: 80px;">{{ record.invMeasName }}</th>
                  <th style="width: 80px;">{{ record.unitPrice }}</th>
                  <td style="width: 200px">{{ record.remark }}</td>
                </tr>
              </ng-template>
            </p-table>
            <div
              class="primeng-no-data"
              *ngIf="primengTableHelper.totalRecordsCount == 0"
            >
              {{ l("NoData") }}
            </div>
            <div class="primeng-paging-container">
              <p-paginator
                rows="{{ primengTableHelper.defaultRecordsCountPerPage }}"
                #paginator
                (onPageChange)="getMaterials($event)"
                [totalRecords]="primengTableHelper.totalRecordsCount"
                [rowsPerPageOptions]="
                  primengTableHelper.predefinedRecordsCountPerPage
                "
              >
              </p-paginator>
              <span class="total-records-count">
                共计：{{ primengTableHelper.totalRecordsCount }}
              </span>
            </div>
          </div>
          <!-- <Primeng-TurboTable-End> -->
        </div>
      </div>
    </div>
  </div>
  <editMaterialModal
    #editMaterialModal
    (modalSave)="getMaterials($event)"
  ></editMaterialModal>
  <logMaterialModal
    #logMaterialModal
    (modalSave)="getMaterials()"
  ></logMaterialModal>
  <adjustIntoModal
    #adjustIntoModal
    (modalSave)="getMaterials($event)"
  ></adjustIntoModal>
  <adjustOutModal
    #adjustOutModal
    (modalSave)="getMaterials($event)"
  ></adjustOutModal>
  <returnWLModal
    #returnWLModal
    (modalSave)="getMaterials($event)"
  ></returnWLModal>
  <updateMaterialPositionModal
    #updateMaterialPositionModal
    (modalSave)="getMaterials($event)"
  ></updateMaterialPositionModal>
</div>
